<%--
  Created by IntelliJ IDEA.
  User: 陌·笙
  Date: 2019-01-10
  Time: 16:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>顾客退货</title>
    <jsp:include page="/comm/tag.jsp"></jsp:include>
    <script>
        $(function () {
            $("#detail").bootstrapTable({
                url:"/xiaoshou/treeShowArauditorDetails",
                height:600,
                pageSize:15,
                pageNumber:1,
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                sidePagination:'server',
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        seat:$("[name='seat']").val(),
                    };
                    return temp;
                },
                locale:'zh-CN',//中文支持,
                toolbar:'#top',
                columns:[
                    {
                        checkbox:true
                    },
                    {field:"seat",title:"单号",align:"center"},
                    {field:"repertory.repertoryName",title:"商品名称",align:"center"},
                    {field:"repertory.model",title:"手机类型",align:"center"},
                    {field:"repertory.repertoryColor",title:"颜色",align:"center"},
                    {field:"repertory.presetPrice",title:"单价",align:"center"},
                    {field:"adNum",title:"购买数量",align:"center"},
                    {field:"adTotal",title:"总价格",align:"center"},
                    {field:"nums",title:"退货数量",align:"center"},
                    {field:"kenum",title:"可退货数量",align:"center"},
                    {field:"beizhu",title:"备注",align:"center"},
                    {
                        title:"完善",
                        align:"center",
                        formatter:function(value,row,index){
                            return " <button class=\"btn btn-danger\" onclick=\"up('"+index+"','"+row.adId+"')\" > <span class=\"glyphicon glyphicon-plus\"></span>&nbsp;&nbsp;完善</button>&nbsp;&nbsp;&nbsp;"
                        }
                    }
                ]
            })
        })
        function cha() {
            var opts = $("#detail").bootstrapTable("getOptions") ;
            var seat=$("[name='seat']").val();
            var limit = opts.pageSize ;
            var offset = (opts.pageNumber-1) * limit;
            $.ajax({
                url:"/xiaoshou/treeShowArauditorDetails",
                type:"post",
                data:{"seat":seat,'limit':limit,'offset':offset},
                success:function(data){
                    $("#detail").bootstrapTable("load",data);
                }
            })
        }
        function up(index,id){
            $("#detail").bootstrapTable("check",index);//根据索引让该行选中
            $.ajax({
                type:"post",
                url:"/xiaoshou/zhans",
                data:{"id":id},
                success:function(a){
                    if(a.kenum==0){
                        swal("错误！", "该商品已经处理完订单了！", "error");
                    }else{
                        $("#beizhu").val(a.beizhu);
                        $("[name='seats']").val(a.seat);
                        $("[name='kenum']").val(a.kenum);
                        $("[name='repertoryId']").val(a.repertory.repertoryId);
                        $("#shopName").html(a.repertory.repertoryName);
                        $("#shopType").html(a.repertory.model);
                        $("#shopcolor").html(a.repertory.repertoryColor);
                        $("#myModal").modal('show');
                    }
                }
            })
            $("[name='tableId']").val(index);

        }
    </script>
</head>
<body>
<div style="margin-left: 50px;margin-right: 50px">
    <div class="#top" style="margin-top: 30px">
        <div class="col-md-12">
            <form action="" method="post" role="form" class="form-horizontal">
               <div class="col-md-1">
                   <button type="button" class="btn btn-primary btn-info glyphicon glyphicon-save-file" onclick="submits()">退款</button>
               </div>
                <div class="form-group col-md-4">
                    <label for="" style="color: red;font-size: 20px" class="col-lg-7">应退金额:￥<span style="color: red;font-size: 20px" class="totals">0.00</span></label>
                    <label for="" style="color: blue;font-size: 20px" class="col-lg-5">总数量:<span class="nums" style="color: blue;font-size: 20px">0.00</span></label>
                </div>
                <div class="col-md-1 pull-right">
                    <button type="button" class="btn btn-primary btn-info glyphicon glyphicon-search" onclick="cha()">查询</button>
                </div>
                <div class="form-group col-md-4 pull-right">
                    <label for="" class="col-md-4 control-label">单号查询:</label>
                    <div class="col-md-8">
                        <input type="text" class="form-control" name="seat" placeholder="输入单号哦！">
                    </div>
                </div>
            </form>
        </div><%--搜索框--%>
        <table id="detail" class="table-striped"></table>
</div>
    <div class="modal inmodal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated bounceInRight">
                <div class="modal-header">
                    </button>
                    <i class="fa fa-laptop modal-icon"></i>
                    <h4 class="modal-title">录入信息</h4>
                    <small class="font-bold">退货完善信息</small>
                </div>
                <div class="modal-body">
                    <form action="" method="post" role="form" id="myform" class="form-horizontal">
                        <div class="form-group" style="font-size: 15px">
                            <div class="col-md-4">
                                <label for="">商品名称:</label>
                                <label for="" id="shopName">oppoK1</label>
                            </div>
                            <div class="col-md-4">
                                <label for="">商品型号:</label>
                                <label for="" id="shopType">4G+128</label>
                            </div>
                            <div class="col-md-4">
                                <label for="">商品颜色:</label>
                                <label for="" id="shopcolor">黑色</label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2" style="text-align: center">退货数量:</label>
                            <div class="col-md-10">
                                <input type="number" name="stockNum" class="form-control" value="1">
                                <input type="hidden" name="seats" class="form-control">
                                <input type="hidden" name="repertoryId" class="form-control">
                                <input type="hidden" name="kenum" class="form-control">
                                <input type="hidden" name="tableId" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2" style="text-align: center">备注:</label>
                            <div class="col-md-10">
                                <textarea class="form-control" id="beizhu" rows="3" name="beizhu"></textarea>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white closes">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="smt()">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    function smt(){
        var nums=$("[name='stockNum']").val();
        var beizhu=$("[name='beizhu']").val();
        var kenum=$("[name='kenum']").val();
        var seat=$("[name='seats']").val();
        var repertoryId=$("[name='repertoryId']").val();
        var opts = $("#detail").bootstrapTable("getOptions");
        limit = opts.pageSize ;
        offset = (opts.pageNumber-1) * limit;
        if(beizhu==''){
            swal("错误！", "退货请完善备注信息！", "error");
        }else{
            if(nums==0){
                swal("错误！", "请选择退货数量！", "error");
            }else if(nums>kenum){
                swal("错误！", "退货数量已超过可退数量", "error");
            }else{
                $.ajax({
                    type:"post",
                    url:"/xiaoshou/addTh",
                    data:{"limit":limit,"offset":offset,"nums":nums,"beizhu":beizhu,"seat":seat,"repertoryId":repertoryId},
                    success:function(data){
                        $("#detail").bootstrapTable("load",data);
                        $("#detail").bootstrapTable("check",$("[name='tableId']").val());//根据索引让该行选中
                        $("#myModal").modal('hide');
                    }
                })
            }

        }

    }
    $(function(){
        $(".closes").on("click",function () {
            $("#myModal").modal('hide');
        })
    })
    function submits(){
        var rows = $("#detail").bootstrapTable("getSelections") ;
        var seat=$("[name='seat']").val();
        var count=0;
        var ids;
        if(rows.length<1){
            swal("错误！", "请选择要退货的数据！", "error");
        }else{
            $.each(rows,function (index,row) {
                if(row.beizhu==null){
                    swal("错误！", "请完善第"+(index+1)+"行的信息", "error");
                    count++;
                }
                ids=row.adId+",";
            })
        }
        if(count>0){
        }else{
            var opts = $("#detail").bootstrapTable("getOptions");
            limit = opts.pageSize ;
            offset = (opts.pageNumber-1) * limit;
            $.ajax({
                type:"post",
                url:"/xiaoshou/retreat",
                data:{"id":ids,"seat":seat,"limit":limit,"offset":offset},
                success:function(data){
                    $("#detail").bootstrapTable("load",data);
                    swal("已上报", "已上报成功", "success");
                }
            })
        }

    }
    function time(){//每隔一秒触发该事件
        var num=0;
        var total=0;
        var rows = $("#detail").bootstrapTable("getSelections") ;
        $.each(rows,function (index,row) {
            num=num+row.nums;
            total=total+(row.nums*row.repertory.presetPrice);
        })
        $(".totals").html(total);
        $(".nums").html(num);
        num=0;
        total=0;
    }setInterval("time()",1000);
</script>
</body>
</html>
